package com.zh;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
public class Delete {
	private SessionFactory sFactory;
	private Util util;
	
	public SessionFactory getsFactory() {
		return sFactory;
	}
	public void setsFactory(SessionFactory sFactory) {
		this.sFactory = sFactory;
	}
	public Util getUtil() {
		return util;
	}
	public void setUtil(Util util) {
		this.util = util;
	}
	
	public void deleteTable(String tablename ,String id){
		Session session=sFactory.openSession();
		Transaction ts=session.beginTransaction();
		if(tablename.equals("user")){
			User user=(User) (session.get(User.class, id));
			if(user!=null){
				session.delete(user);
			}
		}
		else if(tablename.equals("house")){
			House house=(House)session.get(House.class, id);
			if(house!=null){
				session.delete(house);
			}
		}
		else if(tablename.equals("payment")){
			Payment program=(Payment)session.get(Payment.class, id);
			if(program!=null){
				session.delete(program);
			}
		}
		else if(tablename.equals("level")){
			Level level=(Level)session.get(Level.class, id);
			if(level!=null){
				session.delete(level);
			}
		}
		else if(tablename.equals("repair")){
			Repair repair=(Repair)session.get(Repair.class, id);
			if(repair!=null){
				session.delete(repair);
			}
		}
		else if(tablename.equals("message")){
			Message message=(Message)session.get(Message.class, id);
			if(message!=null){
				session.delete(message);
			}
		}
		ts.commit();
		session.close();
	}


}
